#include "Base.h"
#include "ClientPlayerList.h"

int compClientPlayer(const void *pElement1,const void *pElement2)
{
	CLobbyClientPlayer *pPlayer1 = *(CLobbyClientPlayer **)pElement1;
	CLobbyClientPlayer *pPlayer2 = *(CLobbyClientPlayer **)pElement2;
	return pPlayer1->GetUserId() - pPlayer2->GetUserId();
}

CClientPlayerList::CClientPlayerList(void)
{
}

CClientPlayerList::~CClientPlayerList(void)
{
}

void CClientPlayerList::AddClientPlayer(CLobbyClientPlayer *pClientPlayer)
{
    m_lock.Lock();
	int nGroupIndex = pClientPlayer->m_dwUserId % PlayerList_Group_Count;
	m_arrPlayerList[nGroupIndex].Insert(pClientPlayer, compClientPlayer);
	m_lock.Unlock();
}

void CClientPlayerList::DelClientPlayer(CLobbyClientPlayer *pClientPlayer)
{
	m_lock.Lock();
	int nGroupIndex = pClientPlayer->m_dwUserId % PlayerList_Group_Count;
	m_arrPlayerList[nGroupIndex].Remove(pClientPlayer, compClientPlayer);
	m_lock.Unlock();
}

CLobbyClientPlayer* CClientPlayerList::FindClientPlayer(DWORD dwUserId)
{
	m_lock.Lock();
	int nGroupIndex = dwUserId % PlayerList_Group_Count;
	CLobbyClientPlayer player;
	player.m_dwUserId = dwUserId;
    CLobbyClientPlayer *pPlayer = m_arrPlayerList[nGroupIndex].Find(&player, compClientPlayer);
	m_lock.Unlock();
	return pPlayer;
}


void CClientPlayerList::SendSynProductListMsg(LCProductListMsg &msg)
{
    CObjPtrList<CLobbyClientPlayer> m_arrPlayerList[PlayerList_Group_Count];
}